import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-04-06
 * Time: 21:38
 */
public class demo3 {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(() -> {
            try{
                System.out.println("t1 wait 之前");
                synchronized (locker){
                    locker.wait();
                }
                System.out.println("t1 wait 之后");
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });

        Thread t2 = new Thread(() -> {
            try{
                System.out.println("t2 wait 之前");
                synchronized (locker){
                    locker.wait();
                }
                System.out.println("t2 wait 之后");
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });


        Thread t3 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入任意内容，唤醒一个线程");
            scanner.next();
            //唤醒所有线程
            /*synchronized (locker){
                locker.notifyAll();
            }*/
            synchronized (locker){
                locker.notify();
            }

            System.out.println("输入任意内容，唤醒另一个线程");
            scanner.next();
            synchronized (locker){
                locker.notify();
            }
        });

        t1.start();
        t2.start();
        t3.start();
    }
}
